package hczc.longcai.com.hccrowdfunding.home.first_index.fragments;

import android.content.Intent;
import android.os.Bundle;

import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import hczc.longcai.com.hccrowdfunding.R;
import hczc.longcai.com.hccrowdfunding.application.BaseApplication;
import hczc.longcai.com.hccrowdfunding.home.first_index.activities.ShowProjectActivity;


public class BottomFragment extends Fragment implements View.OnClickListener, View.OnTouchListener {


    private RelativeLayout flashSale;
    private RelativeLayout newest;
    private RelativeLayout composite;

    private ImageView salePic;
    private ImageView newPic;
    private ImageView comPic;

    public BottomFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_bottom, container, false);
        BaseApplication.scaleScreenHelper.loadView(((ViewGroup) view));

        initViews(view);
        return view;
    }

    private void initViews(View view) {
        flashSale = ((RelativeLayout) view.findViewById(R.id.index_bottom_flashsale));
        salePic = ((ImageView) view.findViewById(R.id.index_bottom_flashsale_pic));
        flashSale.setOnClickListener(this);
        flashSale.setOnTouchListener(this);
        newest = ((RelativeLayout) view.findViewById(R.id.index_bottom_newest));
        newPic = ((ImageView) view.findViewById(R.id.index_bottom_newest_pic));
        newest.setOnClickListener(this);
        newest.setOnTouchListener(this);
        composite = ((RelativeLayout) view.findViewById(R.id.index_bottom_composite));
        comPic = ((ImageView) view.findViewById(R.id.index_bottom_composite_pic));
        composite.setOnClickListener(this);
        composite.setOnTouchListener(this);
        initPics();
    }

    private void initPics() {

    }


    @Override
    public void onClick(View view) {

        int index = view.getId();

        Intent intent = new Intent(getActivity(), ShowProjectActivity.class);
        Bundle bundle = new Bundle();

        switch (index) {

            case R.id.index_bottom_flashsale:
                bundle.putString("title", "限时抢购");
                break;

            case R.id.index_bottom_newest:
                bundle.putString("title", "最新上线");
                break;

            case R.id.index_bottom_composite:
                bundle.putString("title", "综合推荐");
                break;

        }

        intent.putExtras(bundle);
        startActivity(intent);

    }

    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {

        view.setPressed(true);

        return false;

    }
}